/*================================================================
*   Copyright (C) 2014 All rights reserved.
*   
*   文件名称：Log.h
*   创 建 者：Zhang Yuanhao
*   邮    箱：bluefoxah@gmail.com
*   创建日期：2014年09月10日
*   描    述：
*
#pragma once
================================================================*/

#ifndef __LOG_H__
#define __LOG_H__

#include "ostype.h"
#include "Lock.h"
#include <stdio.h>
#ifndef _WIN32
#include <unistd.h>
#endif

#define DEFAULT_LOG_PATH    "log"

#define LOG_FILE_NAME               "im.log"

typedef enum
{
    LOG_DEBUG        = 0,
    LOG_INFO,
    LOG_WARN,
    LOG_ERROR,
    
    
    LEVEL_COUNT,
} LOG_LEVEL;

#define MAX_LOG_FILE_SIZE	0x8000000	// 128MB

class CLog
{
public:
    static CLog* getInstance();
    bool Init(const char* pPath = NULL);
    virtual ~CLog();
    void writeLog(const char* content);
    
private:
    CLog():m_bInited(false) { gethostname(m_szHost,sizeof(m_szHost)); };
    bool isSameDay(const time_t t1, const time_t t2);
    bool InitLog();
private:
    static  CLog* m_pInstance;
    char    m_szPath[128];
    FILE*   m_pFile;
    FILE*   m_pFileLocal;
    uint32_t m_nFileIndex;
    bool    m_bInited;
    time_t  m_lastTime;
    char    m_szHost[64];
};

void sysLog(const char* fmt, ...);
void init_log(bool bUseLock = false);

#endif
